<template>
	<view class="searchbg">
		<image src="../../static/cg.png" mode=""></image>

		<up-transition :show="isnext" mode="slide-down">
			<view class="searchbox">
				<image src="@/static/index/fdj.png" mode=""></image>
				<input type="text" placeholder="请输入第二位名字,编号" v-model="keyword2" />
				<view class="searchbtn2" @click="sure(2)">搜索</view>
			</view>
		</up-transition>


		<view class="searchbox" v-if="!isnext">
			<image src="@/static/index/fdj.png" mode=""></image>
			<input type="text" placeholder="请输入第一位名字,编号" v-model="keyword" />
			<view class="searchbtn2" @click="sure(1)">搜索</view>
		</view>
	</view>
	<view class="reslut"></view>
	<view class="listbg" v-if="list1.length">
		<view class="listcemter">第一位待选名单</view>
		<view class="listbgbox">
			<view @click="setid(item.id,1)" :class="item.id==id1?'listitem active':'listitem'"
				v-for="(item,index) in list1" :key="index">
				<view class="item">
					<text>{{item.name}}</text>
					<text>{{item.id}}</text>
				</view>
			</view>
		</view>
		<block v-if="list2.length">
			<view class="listcemter" style="margin-top: 30rpx;">第二位待选名单</view>
			<view class="listbgbox">
				<view @click="setid(item.id,2)" :class="item.id==id2?'listitem active':'listitem'"
					v-for="(item,index) in list2" :key="index">
					<view class="">
						<text>{{item.name}}</text>
						<text>{{item.id}}</text>
					</view>
				</view>
			</view>
		</block>

	</view>
	<view class="searchbtn" @click="lock" v-if="list1.length&&!isnext">确定</view>
	<view class="searchbtn" @click="chaxun" v-if="id1&&id2">查询</view>
	<view class="" style="height: 30rpx;"></view>




</template>

<script setup>
	import {
		ref
	} from 'vue';
	import {
		familyList
	} from "@/api/ancestra.js"
	import {
		familyRecognizeRelatives
	} from "@/api/account.js"

	let keyword = ref('')
	let keyword2 = ref('')

	let list1 = ref(uni.getStorageSync('userInfo') ? [{
		name: uni.getStorageSync('userInfo').userName,
		id: uni.getStorageSync('userInfo').userId
	}] : [])

	let id1 = ref(uni.getStorageSync('userInfo').userId)
	let id2 = ref('')
	let list2 = ref([])
	let isnext = ref(false)
	let pcShow = ref(false)

	function lock() {
		let it = null
		list1.value.forEach(item => {
			if (item.id == id1.value) {
				it = item
			}
		})
		list1.value = [it]

		isnext.value = true
	}

	function setid(e, type) {
		if (type == 1) {
			id1.value = e
		} else {
			id2.value = e
		}
	}


	function chaxun() {
		uni.showLoading({
			mask: true
		})
		familyRecognizeRelatives({
			id1: id1.value,
			id2: id2.value
		}).then(res => {
			uni.hideLoading()
			uni.navigateTo({
				url: "/pages/book/rqResult?data=" + encodeURIComponent(JSON.stringify(res.data))
			})
		})

	}


	function sure(e) {
		let txt = e == 1 ? keyword.value : keyword2.value
		if (!txt) {
			uni.showToast({
				title: "请输入名字",
				icon: "none"
			})
			return
		}
		uni.showLoading({
			mask: true
		})

		familyList({
			keyword: txt,
			parent: false
		}).then(res => {

			uni.hideLoading()
			if (e == 1) {
				list1.value = res.data
			} else {
				list2.value = res.data
			}
		})
	}
</script>
<style>
	/* 	page{
		background: #f6f6f6;
	} */
</style>

<style scoped lang="scss">
	.resinfo {
		border-radius: 20rpx;
		width: 540rpx;
		height: auto;
		padding: 20rpx;
		box-sizing: border-box;

	}

	.listbg {
		// margin-left: 30rpx;
		width: 690rpx;
		background: #FFFFFF;
		margin-left: 30rpx;
		// margin-top: 24rpx;
		display: flex;
		flex-wrap: wrap;
		margin-bottom: 24rpx;
		border-radius: 16rpx;
		box-sizing: border-box;
		padding: 30rpx;

		.listcemter {
			font-family: PingFang-SC, PingFang-SC;
			font-weight: 500;
			font-size: 24rpx;
			color: #333333;
		}

		.listbgbox {

			display: flex;
			flex-wrap: wrap;
			width: 100%;
		}

		.active {
			border: 1rpx solid #A9070C;
		}

		.listitem {
			margin-top: 30rpx;
			width: 300rpx;
			height: 110rpx;
			background: #EDE7DB;
			// margin-left: 30rpx;
			display: flex;
			align-items: center;
			box-sizing: border-box;
			padding: 0 16rpx;

			.item {
				display: flex;
				flex-direction: column;
			}

			&>image {
				width: 28rpx;
				height: 28rpx;
			}

			&>view {
				text:nth-of-type(1) {
					font-weight: bold;
					font-size: 26rpx;
				}

				text {
					font-size: 24rpx;
					// font-weight: bold;
				}
			}
		}

		.listitem:nth-child(even) {
			margin-left: 30rpx;
		}
	}

	.ssjg {
		margin-left: 30rpx;
		font-size: 28rpx;
		font-weight: bold;
		margin-top: 60rpx;
	}

	.searchbtn {
		width: 340rpx;
		height: 100rpx;
		background: #FFFFFF;
		border-radius: 10rpx;
		margin: 0 auto;
		display: flex;
		align-items: center;
		justify-content: center;

		background: #A9070C;
		color: #ffffff;
		position: relative;
	}

	.searchbtn::after {
		width: 320rpx;
		height: 80rpx;
		border-radius: 10rpx;
		display: block;
		content: '';
		border: 1rpx solid #ffffff;
		position: absolute;
	}

	.searchbtn2 {
		width: 160rpx;
		height: 76rpx;
		background: #FFFFFF;
		border-radius: 10rpx;
		margin: 0 auto;
		display: flex;
		align-items: center;
		justify-content: center;
		background: #A9070C;
		color: #ffffff;
		position: relative;
	}

	.searchbg {
		width: 100%;
		height: auto;
		position: relative;
		box-sizing: border-box;
		padding-top: 440rpx;

		&>image {
			width: 100%;
			height: 500rpx;
			position: absolute;
			z-index: 1;
			top: 0;
			left: 0;
		}

		.searchbox {
			width: 690rpx;
			margin-left: 30rpx;
			height: 120rpx;
			position: relative;
			z-index: 999;
			margin-bottom: 40rpx;
			background: #ffffff;
			display: flex;
			align-items: center;

			transition: all .5s;
			// justify-content:space-between;
			box-sizing: border-box;
			padding: 0 30rpx;
			border-radius: 20rpx;
			box-shadow: 4rpx 0rpx 8rpx 0rpx rgba(0, 0, 0, 0.2);


			image {
				width: 40rpx;
				height: 40rpx;
			}

			input {
				flex: 1;
				margin-left: 10rpx;
			}

		}
	}
</style>